﻿using CTP.CRM.Core.Common.SharedModel.Pub;
using CTP.CRM.Core.CurrentUs.Dtos;
using CTP.CRM.Core.Localization;
using CTP.CRM.Core.SharedModel;
using CTP.CRM.Core.SharedModel.Options;
using System.Text;
using Volo.Abp.AutoMapper;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.Security.Encryption;
using Volo.Abp.Validation.Localization;
using Volo.Abp.VirtualFileSystem;

namespace CTP.CRM.Core
{
    [DependsOn(new Type[]
{
    typeof(AbpAutoMapperModule),
    typeof(AbpLocalizationModule),
    typeof(AbpVirtualFileSystemModule)
})]
    public class CtpAbpCodeModule : AbpModule
    {
        public override void PreConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddHealthChecks();
            Configure(delegate (AbpAutoMapperOptions options)
            {
                options.AddMaps<CtpAbpCodeModule>(validate: true);
            });
            Configure(delegate (AbpVirtualFileSystemOptions options)
            {
                options.FileSets.AddEmbedded<CtpAbpCodeModule>("CTP.CRM.Core");
            });
            Configure(delegate (AbpLocalizationOptions options)
            {
                options.Resources.Add<CtpBasicLocalization>("zh").AddBaseTypes(typeof(AbpValidationResource)).AddVirtualJson("/Localization/Resources/Basic");
            });
        }

        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            Configure<AbpStringEncryptionOptions>(opts =>
            {
                opts.DefaultPassPhrase = "MyStrongPassPhrase"; //用于加密/解密文本的默认密码
                opts.DefaultSalt = Encoding.UTF8.GetBytes("MyStrongSalt");//在加密/解密时用作盐的值。
            });
            Configure<UserCenterTokenOption>(opts =>
            {
                opts.ClaimIsEncryption = true;
                opts.Environment = CTPABPCore.Configuration["Environment"]!;
            });
            UserCenterServiceProvider.ServiceDescriptors = context.Services;
            context.Services.AddScoped<CurrentUser>(_ =>
            {
                return ReqHeaderResolveHelper.GetRequestUserInfo();
            });
        }
    }
}
